<script>
	export default {
		globalData: {
			// hostUrl: 'https://guomai.sxruanjian.cn', //正式地址
			// hostUrl:  'https://gm.sxruanjian.cn',  //陕西国脉
			// hostUrl:  'https://gmjy.sxruanjian.cn', //内蒙国脉
			// hostUrl:  'https://gmcs.sxruanjian.cn',  //国脉测试
			// hostUrl:  'https://gmsaas.sxruanjian.cn',  //国脉sass端
			// hostUrl:  'https://scgm.sxruanjian.cn',  // 四川国脉
			// hostUrl:  'https://jsgm.sxruanjian.cn',  // 江苏国脉
			// hostUrl:  'https://sdgm.sxruanjian.cn',  // 山东国脉
			hostUrl: 'https://zczg.sxruanjian.cn', // 酒馆
			statusBarHeight: 0,
			headAllHeight: 0,
			windowHeight: 0,
			windowWidth: 0,
			code: '',
			open_id: '',
			parent_sn: 0
		},
		onLaunch: function() {
			console.log('App Launch')
			const that = this
			let systemInfo = uni.getSystemInfoSync();
			that.globalData.statusBarHeight = systemInfo.statusBarHeight;
			that.globalData.platform = systemInfo.platform;
			that.globalData.headAllHeight = that.globalData.statusBarHeight + 44;
			that.globalData.windowHeight = systemInfo.windowHeight;
			that.globalData.windowWidth = systemInfo.windowWidth;
			console.log('that.globalData.headAllHeight', that.globalData.headAllHeight)
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			globalRequest(param) {
				var token;
				if (this.getPlatform() == 'mpWx') {
					token = uni.getStorageSync('token')
				} else {
					token = 'oXPca5HMUMFLVCOLn60nijoKGX9c'
				}
				return new Promise((resolve, reject) => {
					uni.request({
						url: `${this.globalData.hostUrl}/${param.api}`,
						method: param.method || "GET",
						timeout: 10000,
						dataType: 'json',
						header: {
							'Authorization': token
						},
						data: param.data,
						success(res) {
							uni.hideLoading()
							if (res.data.code == 419) {
								uni.clearStorageSync()
								/* uni.navigateTo({
									url: '/pages/user/login/login_auth'
								}) */
							}
							resolve(res.data)
						},
						fail(err) {
							uni.hideLoading()
							reject(err)
						}
					})
				})
			},
			getApi() {
				const apiUrl = {
					public: {
						islogin: 'api/isLogin'
					},
					upload: {
						upload: 'api/upload'
					},
					about: {
						about: 'api/aboutUs'
					},
					loginApi: {
						login: 'api/login',
						wxLogin: 'api/loginAuth',
						getxieYi: 'api/xieYi',
						checkBindMobile: 'api/checkBindMobile'
					},
					mall: {
						goodList: 'api/goodsList',
						shareGoods: 'api/goodShareImg',
						shareGoodsList: 'api/divi_list',
						dividendOrderList: 'api/dividendOrderList',
						dividend_statistics: 'api/dividend_statistics',
						getAgreement: 'api/getAgreement'
					},
					home: {
						bindUfid: 'api/bindUfid',
						sliderList: 'api/navigation',
						goods: 'api/homeProducts'
					},
					goodsdata: {
						goodsDetail: 'api/goodsDetail',
						productOrder: 'api/preOrder',
						orderBuys: 'api/orderBuy',
						lunBoDetail:'api/lunBoDetail'
					},
					cartApi: {
						saveCart: 'api/editCart',
						cartList: 'api/userCartList',
						cartDel: 'api/deleteCart'
					},
					user: {
						historyList: 'api/historyList',
						getPoint: 'api/getPoint',
						savePuahInfo: 'api/savePuahInfo',
						cancelOrder: 'api/cancelOrder',
						repeatPay: 'api/repeatPay',
						getUserInfo: 'api/userProfile',
						getStoreAddress: 'api/getStore',
						addressList: 'api/shippingAddress',
						editaddress: 'api/editShip',
						addressDetail: 'api/detailShip',
						handleAddress: 'api/addShip',
						defaultAddress: 'api/setDefaultShip',
						editAlipay: 'api/accountUpdate',
						deteleaddress: 'api/delShip',
						updateMsg: 'api/bindInfo',
						inviteCode: 'api/getMyQrCode',
						getMobile: 'api/bindPhone',
						vipGrade: 'api/userInterests',
						getExchange: 'api/rechargePageData',
						getRechange: 'api/balanceRecharge',
						cursh: 'api/beforeWithDraw',
						getscursh: 'api/withdraw',
						getApplyService: 'api/getApplyService',
						getYuEcursh: 'api/apply',
						getYuEtransfer: 'api/balance_gsts',
						getYuEtransferDetail: 'api/gsts_log',
						orderList: 'api/orderList',
						orderDetail: 'api/orderDetail',
						comfireOrder: 'api/deliveryOrderGood',
						getKufu: 'api/kefu',
						yueDetail: 'api/userBalanceRecord',
						commssionLists: 'api/commssionList',
						TeamCenter: 'api/userTeamCenter',
						TeamCenterDetail: 'api/userChildDetail',
						takeDetail: 'api/deliveryDetail',
						resources: 'api/resouceImageList',
						dividendValLog: 'api/dividendValLog',
						saveInfo: 'api/saveInfo',
						myTeam:'api/myTeam',
						childOrder:'api/childOrder',
						subsidyDetail:'api/subsidyDetail',
						comStatDetail:'api/comStatDetail',
						readXieYi:'api/readXieYi'
					}
				}
				return apiUrl
			},
			getPlatform() {
				let platform = '';
				//#ifdef H5
				platform = 'h5'
				//#endif
				//#ifdef APP-PLUS
				platform = 'AppPlus';
				//#endif
				//#ifdef MP-WEIXIN
				platform = 'mpWx';
				//#endif
				return platform
			},
			//格式化手机号
			formateTel(tel) {
				var reg = /^(\d{3})\d{4}(\d{4})$/;
				return tel.replace(reg, "$1****$2");
			},
			//分隔价格
			splicePrice(price) {
				let priObj = {};
				let priArr = price.toString().split(".");
				if (priArr.length > 1) {
					priObj["intPrice"] = priArr[0];
					priObj["floatPrice"] = `.${priArr[1]}`;
				} else {
					priObj["intPrice"] = priArr[0];
					priObj["floatPrice"] = "";
				};
				return priObj;
			},
			/* 节流函数 */
			throttle(fn, delay) {
				let flag = false,
					timer = null;
				return function() {
					if (flag) return;
					flag = true;
					clearTimeout(timer);
					timer = setTimeout(function() {
						flag = false;
					}, delay)
					fn.apply(this, arguments);
					/* if(flag){
						setTimeout(()=>{
							fn.apply(this,arguments);
							flag = true;
						},delay)
						flag = false;
					} */
				}
			},
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	html,
	body {
		background: $dis-bg-color;
		font-size: $dis-font-size;
		color: #333;
		font-size: 28rpx;
	}

	@font-face {
		font-family: 'DIN-BOLD';
		src: url(https://front.sxruanjian.cn/ttf/DIN-BOLD.TTF) format('truetype');
	}


	uni-toast {
		z-index: 100000000000 !important;
	}

	.line_center {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.line_h_center {
		display: flex;
		align-items: center;
	}

	uni-button {
		position: relative;
		display: block;
		margin-left: inherit;
		margin-right: inherit;
		padding-left: 0;
		padding-right: 0;
		box-sizing: border-box;
		font-size: inherit;
		text-align: inherit;
		text-decoration: none;
		line-height: inherit;
		border-radius: inherit;
		-webkit-tap-highlight-color: inherit;
		overflow: hidden;
		color: #000;
		background-color: inherit;
		cursor: pointer;
	}

	uni-button:after {
		content: "";
		width: 0;
		height: 0;
		position: absolute;
		top: 0;
		left: 0;
		border: inherit;
		box-sizing: border-box;
		border-radius: inherit;
		background: transparent;
	}

	uni-button[disabled]:not([type]),
	uni-button[disabled][type=default] {
		color: rgba(0, 0, 0, .3);
		/* background-color: #f7f7f7 !important; */
	}

	button {
		-webkit-tap-highlight-color: transparent;
		background-color: inherit;
		border-radius: inherit;
		box-sizing: border-box;
		color: inherit;
		cursor: pointer;
		display: block;
		font-size: inherit;
		line-height: inherit;
		margin-left: auto;
		margin-right: auto;
		overflow: hidden;
		padding-left: 0;
		padding-right: 0;
		position: relative;
		text-align: center;
		text-decoration: none;
	}

	button::after {
		border: 0;
	}

	/* 去除scrollview滚动条 不支持nvue页面 */
	::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}

	.distributor-anim {
		-webkit-animation-duration: .3s;
		animation-duration: .3s;
		-webkit-animation-fill-mode: both;
		animation-fill-mode: both
	}

	.distributor-anim-rotate {
		-webkit-animation-name: distributor-rotate;
		animation-name: distributor-rotate;
		-webkit-animation-duration: 2s;
		animation-duration: 2s;
		-webkit-animation-timing-function: linear;
		animation-timing-function: linear
	}

	.distributor-anim-loop {
		-webkit-animation-iteration-count: infinite;
		animation-iteration-count: infinite
	}

	@-webkit-keyframes distributor-rotate {
		from {
			-webkit-transform: rotate(0)
		}

		to {
			-webkit-transform: rotate(360deg)
		}
	}

	@keyframes distributor-rotate {
		from {
			transform: rotate(0)
		}

		to {
			transform: rotate(360deg)
		}
	}
</style>